home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENCRYPT.SWG / 0012_PATCHEXE.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  71 lines

  1. { PD> This looks like something I would like to add to my Programs.  My
  2.  PD> question is, how do you modify the .exe from the Program.  I can do the
  3.  PD> encryption but don't know how to store the encrypted passWords in the
  4.  PD> Program's own .exe.  Any help would be appreciated.
  5. }
  6.  
  7. Procedure PatchExeFile(ItemAddr:Pointer;itemsize:LongInt);
  8. Var
  9.   FiletoPatch : File;
  10.   HeaderSize  : Word;
  11.   seeksize    : LongInt;
  12.   offset      : Word;
  13.   LDseg       : LongInt;
  14.   ch          : Char;
  15.  
  16. begin
  17.   assign(FiletoPatch, paramstr(0));
  18.   reset(FiletoPatch, 1);
  19.   seek(FiletoPatch, 8);
  20.   blockread(Filetopatch, headersize, sizeof(headersize));
  21.   offset := ofs(itemAddr^);
  22.   Ldseg := LongInt(Dseg);
  23.   seeksize := 16 * (LDseg - PrefixSeg + HeaderSize) + offset - 256
  24.     seek(Filetopatch, seeksize);
  25.   blockWrite(Filetopatch, ItemAddr^, ItemSize);
  26.   close(Filetopatch);
  27. end;
  28.  
  29. {Call it this way:
  30. }
  31. PatchExeFile(Addr(passWords), sizeof(passWords));
  32.  
  33. {note that For this to work, passWords must be a TypeD ConstANT.
  34. So you declare it this way:
  35. }
  36.   PassWords : PassWord_Array =
  37.   (
  38.     (PassWord : #247#154#189#209#18#104#143#29; Protected : False),
  39.     .
  40.     .
  41.     .
  42.     (PassWord : #247#154#189#209#18#104#143#29; Protected : False)
  43.   );
  44.  
  45. {  PassWord_Array is declard as an Array of PassWord_Record;
  46.  
  47.     The above declaration is from my Crypto.inC. I have a Crypto.PAS
  48. Program that generates this File from my Make File so that on each
  49. Compile the encryption is changed and the Array of passWords is stored
  50. with valid encrypted passWords. I used #<AsciiValue> because the
  51. encryption can generate values from Ascii 0 to Ascii 255 and some of
  52. those cause troubles in Strings Constants using "'" as delimeters.
  53.  
  54.     As long as you use:
  55.  
  56. Const <ConstName> : <ConstType> = <ConstantValue>;
  57.  
  58.     You will be sure PatchExe can find it's correct adress in the EXE.
  59. From there on you can read it in your TP Program as usual and store it
  60. using the call to PatchExe I gave up there.
  61.  
  62.     BTW, do as I do and generate a new random encryption key on each
  63. run, Re-encrypting everything and writting it back to the exe. This
  64. drives Hackers mad when they try to decypher your encrypted passWords.
  65.  
  66. One last note:
  67.     The above PatchExe was written when I used TP 6.0. I haven't checked
  68.     yet if TP 7.0 Uses different mapping of his EXe and it will most
  69.     probably not work on a Protected-mode Compiled EXE.
  70. }
  71.